<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('器材列表')" />
    <th:block th:include="include :: layout-latest-css" />
    <th:block th:include="include :: ztree-css" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: jquery-smartwizard-css" />
</head>
<body class="gray-bg">
<!--    <div class="ui-layout-west">-->
<!--        <div class="box box-main">-->
<!--            <div class="box-header">-->
<!--                <div class="box-title">-->
<!--                    <i class="fa icon-grid"></i> 器材类型-->
<!--                </div>-->
<!--                <div class="box-tools pull-right">-->
<!--                    <a type="button" class="btn btn-box-tool" href="#" onclick="validDeviceType()" title="管理器材类型"><i class="fa fa-edit"></i></a>-->
<!--                    <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>-->
<!--                    <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>-->
<!--                    <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新设备类型"><i class="fa fa-refresh"></i></button>-->
<!--                </div>-->
<!--            </div>-->
<!--            <div class="ui-layout-content">-->
<!--                <div id="tree" class="ztree"></div>-->
<!--            </div>-->
<!--        </div>-->
<!--    </div>-->
    <div class="ui-layout-center">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>器材类型：</label>
                                <div class="input-group">
                                    <input name="name" onclick="gotoSelectValidDeviceTypeTree()" autocomplete="off"  id="name" type="text" placeholder="请选择器材类型" >
<!--                                    <span class="input-group-addon"><i class="fa fa-search"></i></span>-->
                                    <input type="text" name="deviceTypeId"  id="deviceTypeId"  autocomplete="off" hidden/>
                                </div>
                            </li>
                            <li>
                                <label>器材型号：</label>
                                <div class="input-group">
                                    <div>
                                        <input id="searchDeviceMode" placeholder="请输入器材型号名称"   autocomplete="off"  type="text" required maxlength="30">
                                        <input type="hidden" name="modeId" id="modeId" autocomplete="off" />
                                        <div class="input-group-btn">
                                            <button type="button" class="btn btn-white dropdown-toggle" data-toggle="dropdown">
                                                <span class="caret"></span>
                                            </button>
                                            <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                            </ul>
                                        </div>
                                    </div>
                                </div>
                            </li>
                            <li>
                                <label>器材编号：</label>
                                <div class="input-group">
                                <input type="text" name="serialNumber" autocomplete="off" />
                                </div>
                            </li>
                            <li>
                                <label>备注：</label>
                                <div class="input-group">
                                <input type="text" name="note" autocomplete="off" />
                                </div>
                            </li>
                            <li>
                                <label>状态：</label>
<!--                                <input type="text" name="valid"/>-->
                                <div class="input-group">
                                    <select name="valid" th:with="type=${@dict.getType('sys_device_valid')}">
                                        <option value="">所有</option>
                                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                    </select>
                                </div>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:device:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:device:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
<!--                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:device:remove">-->
<!--                    <i class="fa fa-remove"></i> 删除-->
<!--                </a>-->
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:device:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
     </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: layout-latest-js" />
    <th:block th:include="include :: ztree-js" />
    <th:block th:include="include :: select2-js" />
    <th:block th:include="include :: bootstrap-suggest-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:device:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:device:remove')}]];
        var prefix = ctx + "system/device";

        $(function() {
            // var panehHidden = false;
            // if ($(this).width() < 769) {
            //     panehHidden = true;
            // }
            // $('body').layout({ initClosed: panehHidden, west__size: 185 });
            // // 回到顶部绑定
            // if ($.fn.toTop !== undefined) {
            //     var opt = {
            //         win:$('.ui-layout-center'),
            //         doc:$('.ui-layout-center')
            //     };
            //     $('#scroll-up').toTop(opt);
            // }
            queryDeviceList();
            // getValidDeviceTypeTree();
        });
        var deviceValidDatas = [[${@dict.getType('sys_device_valid')}]];
        var unitDatas = [[${@dict.getType('sys_unit')}]];
        function queryDeviceList(){
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "器材",
                columns: [{
                    radio: true
                },
                    {
                        field: 'id',
                        title: '主键ID',
                        visible: false
                    },
                    {
                        field: 'typeName',
                        title: '器材类型'
                    },
                    {
                        field: 'modeName',
                        title: '器材型号'
                    },
                    {
                        field: 'serialNumber',
                        title: '器材编号'
                    },
                    {
                        field: 'unit',
                        title: '单位',
                        formatter:function (value,row,index){
                            return $.table.selectDictLabel(unitDatas, value);
                        }
                    },
                    {
                        field: 'note',
                        title: '备注'
                    },
                    {
                        field: 'valid',
                        title: '状态',
                        formatter:function (value,row,index){
                            return $.table.selectDictLabel(deviceValidDatas, value);
                        }
                    },
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function(value, row, index) {
                            var actions = [];
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            // actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                            return actions.join('');
                        }
                    },
                    {
                        field: 'createTime',
                        title: '创建时间'
                    }, {
                        field: 'updateTime',
                        title: '最近更新时间'
                    }]
            };
            $.table.init(options);
        }

        function getValidDeviceTypeTree() {
            var url = ctx + "system/type/getValidDeviceTypeTree";
            var options = {
                url: url,
                expandLevel: 2,
                onClick : zOnClick
            };
            $.tree.init(options);

            function zOnClick(event, treeId, treeNode) {
                $("#typeId").val(treeNode.id);
                $("#typeName").val(treeNode.name);
                $.table.search();
            }
        }

        /* 设备管理-设备类型 */
        function validDeviceType() {
            var url = ctx + "system/type";
            $.modal.openTab("器材类型管理", url);
        }
        $('#btnRefresh').click(function() {
            getValidDeviceTypeTree();
        });
        $('#btnExpand').click(function() {
            $._tree.expandAll(true);
            $(this).hide();
            $('#btnCollapse').show();
        });

        $('#btnCollapse').click(function() {
            $._tree.expandAll(false);
            $(this).hide();
            $('#btnExpand').show();
        });

        /* 器材管理-选择器材类型名称 */
        function gotoSelectValidDeviceTypeTree() {
            var url = ctx + "system/type/gotoDeptTree";
            var options = {
                title: '选择器材类型',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }
        function doSubmit(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            var body = layer.getChildFrame('body', index);
            $("#typeId").val(body.find('#deviceTypeId').val());
            $("#typeName").val(body.find('#deviceTypeName').val());
            layer.close(index);
        }
        // 器材型号自动补全 start
        var customerResult;
        var testBsSuggest = $("#searchDeviceMode").bsSuggest({
            allowNoKeyword: false, //是否允许无关键字时请求数据
            multiWord: false, //以分隔符号分割的多关键字支持
            url: "http://"+window.location.host + "/system/mode/queryValidModeByParam?typeId="+$('#deviceTypeId').val()+"&modeName=",
            getDataMethod: "url", //获取数据的方式，总是从 URL 获取
            effectiveFields: ["modeName"],
            searchFields: [ "modeName"],
            effectiveFieldsAlias:{modeName: "器材型号"},
            clearable: true,
            showBtn: false,
            idField: "id",
            keyField: "modeName"
        }).on('onDataRequestSuccess', function (e, result) {
            customerResult = result.value;
        }).on('onSetSelectValue', function (e, keyword) {
            $("#modeId").val(keyword.id);
            $("#modeName").val(keyword.key);
        }).on('onUnsetSelectValue', function (e) {
            $("#modeId").val(0);
            $("#modeName").val("");
        });
        // 客户自动补全 end
    </script>
</body>
</html>